Builder

open class Builder(source)

Builder class for NotificationCompat objects. Allows easier control over all the flags, as well as help constructing the typical notification layouts.

On platform versions that don't offer expanded notifications, methods that depend on expanded notifications have no effect.

For example, action buttons won't appear on platforms prior to Android 4.1. Action buttons depend on expanded notifications, which are only available in Android 4.1 and later.

For this reason, you should always ensure that UI controls in a notification are also available in an android.app.Activity in your app, and you should always start that android.app.Activity when users click the notification. To do this, use the setContentIntent() method.

Constructors

Link copied to clipboard
constructor(@NonNull context: @NonNull Context, @NonNull notification: @NonNull Notification)
Creates a NotificationCompat.Builder which can be used to build a notification that is equivalent to the given one, such that updates can be made to an existing notification with the NotificationCompat.Builder API.
constructor(@NonNull context: @NonNull Context, @NonNull channelId: @NonNull String)
Constructor.
constructor(@NonNull context: @NonNull Context)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var mPersonList: @NonNull ArrayList<Person>

Functions

Link copied to clipboard
@NonNull
open fun addAction(@Nullable action: @Nullable NotificationCompat.Action): @NonNull NotificationCompat.Builder
@NonNull
open fun addAction(icon: Int, @Nullable title: @Nullable CharSequence, @Nullable intent: @Nullable PendingIntent): @NonNull NotificationCompat.Builder
Add an action to this notification.
Link copied to clipboard
@NonNull
open fun addExtras(@Nullable extras: @Nullable Bundle): @NonNull NotificationCompat.Builder
Merge additional metadata into this notification.
Link copied to clipboard
@RequiresApi(value = 21)
@NonNull
open fun addInvisibleAction(@Nullable action: @Nullable NotificationCompat.Action): @NonNull NotificationCompat.Builder
@RequiresApi(value = 21)
@NonNull
open fun addInvisibleAction(icon: Int, @Nullable title: @Nullable CharSequence, @Nullable intent: @Nullable PendingIntent): @NonNull NotificationCompat.Builder
Add an invisible action to this notification.
Link copied to clipboard
@NonNull
open fun addPerson(@Nullable person: @Nullable Person): @NonNull NotificationCompat.Builder
@NonNull
open fun addPerson(@Nullable uri: @Nullable String): @NonNull NotificationCompat.Builder
Add a person that is relevant to this notification.
Link copied to clipboard
@NonNull
open fun build(): @NonNull Notification
Combine all of the options that have been set and return a new Notification object.
Link copied to clipboard
@NonNull
open fun clearActions(): @NonNull NotificationCompat.Builder
Clear any actions added via addAction
Link copied to clipboard
Clear any invisible actions added via addInvisibleAction
Link copied to clipboard
@NonNull
open fun clearPeople(): @NonNull NotificationCompat.Builder
Clear any people added via either addPerson or addPerson
Link copied to clipboard
@Nullable
open fun createBigContentView(): @Nullable RemoteViews
Construct a RemoteViews for the final big notification layout.
Link copied to clipboard
@Nullable
open fun createContentView(): @Nullable RemoteViews
Construct a RemoteViews for the final notification layout.
Link copied to clipboard
@Nullable
open fun createHeadsUpContentView(): @Nullable RemoteViews
Construct a RemoteViews for the final heads-up notification layout.
Link copied to clipboard
@NonNull
open fun extend(@NonNull extender: @NonNull NotificationCompat.Extender): @NonNull NotificationCompat.Builder
Apply an extender to this notification builder.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@NonNull
open fun getExtras(): @NonNull Bundle
Get the current metadata Bundle used by this notification Builder.
Link copied to clipboard
@NonNull
open fun getNotification(): @NonNull Notification
Link copied to clipboard
Link copied to clipboard
return when if it is showing or 0 otherwise
Link copied to clipboard
Determines whether the platform can generate contextual actions for a notification.
Link copied to clipboard
@NonNull
open fun setAutoCancel(autoCancel: Boolean): @NonNull NotificationCompat.Builder
Setting this flag will make it so the notification is automatically canceled when the user clicks it in the panel.
Link copied to clipboard
@NonNull
open fun setBadgeIconType(icon: Int): @NonNull NotificationCompat.Builder
Sets which icon to display as a badge for this notification.
Link copied to clipboard
@NonNull
open fun setBubbleMetadata(@Nullable data: @Nullable NotificationCompat.BubbleMetadata): @NonNull NotificationCompat.Builder
Sets the BubbleMetadata that will be used to display app content in a floating window over the existing foreground activity.
Link copied to clipboard
@NonNull
open fun setCategory(@Nullable category: @Nullable String): @NonNull NotificationCompat.Builder
Set the notification category.
Link copied to clipboard
@NonNull
open fun setChannelId(@NonNull channelId: @NonNull String): @NonNull NotificationCompat.Builder
Specifies the channel the notification should be delivered on.
Link copied to clipboard
@RequiresApi(value = 24)
@NonNull
open fun setChronometerCountDown(countsDown: Boolean): @NonNull NotificationCompat.Builder
Sets the Chronometer to count down instead of counting up.
Link copied to clipboard
@NonNull
open fun setColor(@ColorInt argb: Int): @NonNull NotificationCompat.Builder
Sets color.
Link copied to clipboard
@NonNull
open fun setColorized(colorize: Boolean): @NonNull NotificationCompat.Builder
Set whether this notification should be colorized.
Link copied to clipboard
@NonNull
open fun setContent(@Nullable views: @Nullable RemoteViews): @NonNull NotificationCompat.Builder
Supply a custom RemoteViews to use instead of the standard one.
Link copied to clipboard
@NonNull
open fun setContentInfo(@Nullable info: @Nullable CharSequence): @NonNull NotificationCompat.Builder
A small piece of additional information pertaining to this notification.
Link copied to clipboard
@NonNull
open fun setContentIntent(@Nullable intent: @Nullable PendingIntent): @NonNull NotificationCompat.Builder
Supply a PendingIntent to send when the notification is clicked.
Link copied to clipboard
@NonNull
open fun setContentText(@Nullable text: @Nullable CharSequence): @NonNull NotificationCompat.Builder
Set the text (second row) of the notification, in a standard notification.
Link copied to clipboard
@NonNull
open fun setContentTitle(@Nullable title: @Nullable CharSequence): @NonNull NotificationCompat.Builder
Set the title (first row) of the notification, in a standard notification.
Link copied to clipboard
@NonNull
open fun setCustomBigContentView(@Nullable contentView: @Nullable RemoteViews): @NonNull NotificationCompat.Builder
Supply custom RemoteViews to use instead of the platform template in the expanded form.
Link copied to clipboard
@NonNull
open fun setCustomContentView(@Nullable contentView: @Nullable RemoteViews): @NonNull NotificationCompat.Builder
Supply custom RemoteViews to use instead of the platform template.
Link copied to clipboard
@NonNull
open fun setCustomHeadsUpContentView(@Nullable contentView: @Nullable RemoteViews): @NonNull NotificationCompat.Builder
Supply custom RemoteViews to use instead of the platform template in the heads up dialog.
Link copied to clipboard
@NonNull
open fun setDefaults(defaults: Int): @NonNull NotificationCompat.Builder
Set the default notification options that will be used.
Link copied to clipboard
@NonNull
open fun setDeleteIntent(@Nullable intent: @Nullable PendingIntent): @NonNull NotificationCompat.Builder
Supply a PendingIntent to send when the notification is cleared by the user directly from the notification panel.
Link copied to clipboard
@NonNull
open fun setExtras(@Nullable extras: @Nullable Bundle): @NonNull NotificationCompat.Builder
Set metadata for this notification.
Link copied to clipboard
@NonNull
open fun setForegroundServiceBehavior(behavior: Int): @NonNull NotificationCompat.Builder
Specify a desired visibility policy for a Notification associated with a foreground service.
Link copied to clipboard
@NonNull
open fun setFullScreenIntent(@Nullable intent: @Nullable PendingIntent, highPriority: Boolean): @NonNull NotificationCompat.Builder
An intent to launch instead of posting the notification to the status bar.
Link copied to clipboard
@NonNull
open fun setGroup(@Nullable groupKey: @Nullable String): @NonNull NotificationCompat.Builder
Set this notification to be part of a group of notifications sharing the same key.
Link copied to clipboard
@NonNull
open fun setGroupAlertBehavior(groupAlertBehavior: Int): @NonNull NotificationCompat.Builder
Sets the group alert behavior for this notification.
Link copied to clipboard
@NonNull
open fun setGroupSummary(isGroupSummary: Boolean): @NonNull NotificationCompat.Builder
Set this notification to be the group summary for a group of notifications.
Link copied to clipboard
@NonNull
open fun setLargeIcon(@Nullable icon: @Nullable Bitmap): @NonNull NotificationCompat.Builder
@RequiresApi(value = 23)
@NonNull
open fun setLargeIcon(@Nullable icon: @Nullable Icon): @NonNull NotificationCompat.Builder
Sets the large icon that is shown in the notification.
Link copied to clipboard
@NonNull
open fun setLights(@ColorInt argb: Int, onMs: Int, offMs: Int): @NonNull NotificationCompat.Builder
Set the argb value that you would like the LED on the device to blink, as well as the rate.
Link copied to clipboard
@NonNull
open fun setLocalOnly(b: Boolean): @NonNull NotificationCompat.Builder
Set whether or not this notification is only relevant to the current device.
Link copied to clipboard
@NonNull
open fun setLocusId(@Nullable locusId: @Nullable LocusIdCompat): @NonNull NotificationCompat.Builder
Sets the LocusIdCompat associated with this notification.
Link copied to clipboard
Silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.
Link copied to clipboard
@NonNull
open fun setNumber(number: Int): @NonNull NotificationCompat.Builder
Sets the number of items this notification represents.
Link copied to clipboard
@NonNull
open fun setOngoing(ongoing: Boolean): @NonNull NotificationCompat.Builder
Set whether this is an ongoing notification.
Link copied to clipboard
@NonNull
open fun setOnlyAlertOnce(onlyAlertOnce: Boolean): @NonNull NotificationCompat.Builder
Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing.
Link copied to clipboard
@NonNull
open fun setPriority(pri: Int): @NonNull NotificationCompat.Builder
Set the relative priority for this notification.
Link copied to clipboard
@NonNull
open fun setProgress(max: Int, progress: Int, indeterminate: Boolean): @NonNull NotificationCompat.Builder
Set the progress this notification represents, which may be represented as a android.widget.ProgressBar.
Link copied to clipboard
@NonNull
open fun setPublicVersion(@Nullable n: @Nullable Notification): @NonNull NotificationCompat.Builder
Supply a replacement Notification whose contents should be shown in insecure contexts (i.e.
Link copied to clipboard
@NonNull
open fun setRemoteInputHistory(text: @Nullable Array<CharSequence>): @NonNull NotificationCompat.Builder
Set the remote input history.
Link copied to clipboard
@NonNull
open fun setRequestPromotedOngoing(requestPromotedOngoing: Boolean): @NonNull NotificationCompat.Builder
Set whether this notification is requesting to be a promoted ongoing notification.
Link copied to clipboard
@NonNull
open fun setSettingsText(@Nullable text: @Nullable CharSequence): @NonNull NotificationCompat.Builder
Provides text that will appear as a link to your application's settings.
Link copied to clipboard
@NonNull
open fun setShortCriticalText(@Nullable shortCriticalText: @Nullable String): @NonNull NotificationCompat.Builder
Sets a very short string summarizing the most critical information contained in the notification.
Link copied to clipboard
@NonNull
open fun setShortcutId(@Nullable shortcutId: @Nullable String): @NonNull NotificationCompat.Builder
From Android 11, messaging notifications (those that use MessagingStyle) that use this method to link to a published long-lived sharing shortcut may appear in a dedicated Conversation section of the shade and may show configuration options that are unique to conversations.
Link copied to clipboard
@NonNull
open fun setShortcutInfo(@Nullable shortcutInfo: @Nullable ShortcutInfoCompat): @NonNull NotificationCompat.Builder
Populates this notification with given ShortcutInfoCompat.
Link copied to clipboard
@NonNull
open fun setShowWhen(show: Boolean): @NonNull NotificationCompat.Builder
Control whether the timestamp set with setWhen is shown in the content view.
Link copied to clipboard
@NonNull
open fun setSilent(silent: Boolean): @NonNull NotificationCompat.Builder
If true, silences this instance of the notification, regardless of the sounds or vibrations set on the notification or notification channel.
Link copied to clipboard
@RequiresApi(value = 23)
@NonNull
open fun setSmallIcon(@NonNull icon: @NonNull IconCompat): @NonNull NotificationCompat.Builder
@NonNull
open fun setSmallIcon(icon: Int): @NonNull NotificationCompat.Builder
Set the small icon to use in the notification layouts.
@NonNull
open fun setSmallIcon(icon: Int, level: Int): @NonNull NotificationCompat.Builder
A variant of setSmallIcon(int) that takes an additional level parameter for when the icon is a LevelListDrawable.
Link copied to clipboard
@NonNull
open fun setSortKey(@Nullable sortKey: @Nullable String): @NonNull NotificationCompat.Builder
Set a sort key that orders this notification among other notifications from the same package.
Link copied to clipboard
@NonNull
open fun setSound(@Nullable sound: @Nullable Uri): @NonNull NotificationCompat.Builder
@NonNull
open fun setSound(@Nullable sound: @Nullable Uri, streamType: Int): @NonNull NotificationCompat.Builder
Set the sound to play.
Link copied to clipboard
@NonNull
open fun setStyle(@Nullable style: @Nullable NotificationCompat.Style): @NonNull NotificationCompat.Builder
Add a rich notification style to be applied at build time.
Link copied to clipboard
@NonNull
open fun setSubText(@Nullable text: @Nullable CharSequence): @NonNull NotificationCompat.Builder
This provides some additional information that is displayed in the notification.
Link copied to clipboard
@NonNull
open fun setTicker(@Nullable tickerText: @Nullable CharSequence): @NonNull NotificationCompat.Builder
@NonNull
open fun setTicker(@Nullable tickerText: @Nullable CharSequence, @Nullable views: @Nullable RemoteViews): @NonNull NotificationCompat.Builder
Sets the "ticker" text which is sent to accessibility services.
Link copied to clipboard
@NonNull
open fun setTimeoutAfter(durationMs: Long): @NonNull NotificationCompat.Builder
Specifies the time at which this notification should be canceled, if it is not already canceled.
Link copied to clipboard
@NonNull
open fun setUsesChronometer(b: Boolean): @NonNull NotificationCompat.Builder
Show the when field as a stopwatch.
Link copied to clipboard
@NonNull
open fun setVibrate(pattern: @Nullable Array<Long>): @NonNull NotificationCompat.Builder
Set the vibration pattern to use.
Link copied to clipboard
@NonNull
open fun setVisibility(visibility: Int): @NonNull NotificationCompat.Builder
Link copied to clipboard
@NonNull
open fun setWhen(when: Long): @NonNull NotificationCompat.Builder
Set the time that the event occurred.